//
//  DFPieChartView.swift
//  MoyoungHome
//
//  Created by 李然 on 2022/9/27.
//

import UIKit
import Charts

public class DFPieChartView:PieChartView{
    
   public override init(frame: CGRect) {
        super.init(frame: frame)
        
        setDefaultChart()
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    private func setDefaultChart(){
        
        self.noDataText = "page_no_data".language
        
        self.usePercentValuesEnabled = true
        self.legend.enabled = false
        self.dragDecelerationFrictionCoef = 0
        self.drawHoleEnabled = true
        self.holeColor = UIColor.clear
        self.holeRadiusPercent = 0.75
        
        self.highlightPerTapEnabled = false
        self.drawEntryLabelsEnabled = false
    }
    

    
    public func setData(_ barDataList:[Double] ,colors:[UIColor], sliceSpace: CGFloat = 2.0){
        let entries:[PieChartDataEntry] = barDataList.map{PieChartDataEntry(value: $0)}
        
        let dataSet = PieChartDataSet.init(entries: entries, label: "")
        dataSet.drawIconsEnabled = false
        dataSet.drawValuesEnabled = false
        dataSet.sliceSpace = sliceSpace
        dataSet.colors = colors
        
        let pieData = PieChartData(dataSet: dataSet)
        self.data = pieData
    }
}
